﻿using System.Collections.Generic;

using Microsoft.WowAddonStudio.Lua.Parser;

namespace Microsoft.WowAddonStudio.Lua.AST
{
    /// <summary>
    /// Represents a for loop node in the AST for the Lua code file.
    /// </summary>
    public class ForLoop : Loop
    {
        ///// <summary>
        /// Initializes a new instance of the <see cref="ForLoop"/> class.
        /// </summary>
        /// <param name="location">The location of the node.</param>
        public ForLoop(LexLocation location)
            : base(location)
        {
        }

        /// <summary>
        /// Gets or sets the identifier used for the iterator variable.
        /// </summary>
        public Identifier Identifier { get; set; }

		/// <summary>
		/// Gets or sets the list of identifiers used in a generic for loop.
		/// </summary>
		/// <value>The identifier list.</value>
        public Identifier IdentifierList { get; set; }

        /// <summary>
        /// Gets the enumerable collection of identifiers declared for the for loop.
        /// </summary>
        /// <returns>An enumerable collection of <see cref="Identifier"/>s.</returns>
        public IEnumerable<Identifier> GetIdentifiers()
        {
            if (Identifier != null)
                yield return Identifier;
            if (IdentifierList != null)
            {
                foreach (Identifier identifier in IdentifierList)
                    yield return identifier;
                }
        }

        /// <summary>
        /// Gets the child nodes of the node.
        /// </summary>
        /// <returns>An enumerable collection of <see cref="Node"/>s.</returns>
        public override IEnumerable<Node> GetChildNodes()
        {
            yield return IdentifierList;
            yield return Expression;
            yield return Block;
        }
	}
}
